Skip to content

[rexm] Improve .log file saving for test command. - #6111

Closed
MatthewRoush wants to merge 4 commits into
raysan5:masterfrom
MatthewRoush:master
Closed

MatthewRoush wants to merge 4 commits into
raysan5:masterfrom
MatthewRoush:master

Conversation

@MatthewRoush

Copy link
Copy Markdown
Contributor

Before, the test command used javascript (client) to save the generated log file, which doesn't allow you to specify a path to save the file to (for security reasons.)

test was already using a python server to run the web example, which we can take advantage of. Using a python script (rexm_web_test_server.py) we can control how we handle POST requests. With that, we can use javascript to send a POST request to the server, and the server can then save the log file (avoiding client restrictions.)

As an added bonus, we don't need FileSaver.js anymore.

Miscellaneous changes

  • Fix tools/rexm/Makefile so that it uses SHELL=cmd on Windows.
  • Change the test command server port number from 8080 to 38080 to reduce conflicts with other programs.

Need to use `cmd` shell for `del`.
When using a port that's already in use, the server fails to start. Using a different (hopefully less common) port should help mitigate this.
Before, the `test` command used javascript (client) to save the generated log file, which doesn't allow you to specify a path to save the file (for security reasons.)

`test` was already using a python server to run the web example, which we can take advantage of. Using a python script (`rexm_web_test_server.py`) we can control how we handle POST requests. With that, we can use javascript to send a POST request to the server, and the server can then save the log file (avoiding client restrictions.)

As an added bonus, we don't need `FileSaver.js` anymore.
Comment thread src/shell.html
// 'Ask where to save each file before downloading' - which you can set true/false.
// If you enable this setting it would always ask you and bring the SaveAsDialog
saveAs(blob, localFSname);
var xhr = new XMLHttpRequest();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it require the Python script?

@raysan5

raysan5 commented Aug 31, 2026

Copy link
Copy Markdown
Owner

@MatthewRoush I don't like FileSaver.js but I prefer to avoid adding a Python script dependency. The XMLHttpRequest proposed requires the Python script?

@MatthewRoush

Copy link
Copy Markdown
Contributor Author

Yes, because we have to implement our own POST handling logic. The primary annoyance with the previous implementation was that it couldn't save a file to a specific path because of browser security restrictions. This means that the file is automatically (or not, if the user has the setting on that makes it prompt every time) saved to the "default" save location, which may not be the traditional "Downloads" directory.

The way to bypass the client-side file saving restrictions is to not save the file from the client, but instead from the server (which is also just the client computer, because it's a localhost://.) The problem is that the default server from running python http.server (which is what we previously did to run the web exmaples) doesn't handle POST requests. That means we have to write our own Python script to implement POST request handling. We also have to handle GET requests since we're using our own request handling logic, as far as I know.

The XMLHttpRequest() sends the POST request from the client to the server, and the Python script (our server) handles that POST request. We can send a POST request containing the .log data, with the URL being the path (relative to the server root) we want to save the .log file to (exBasePath/exCategory/logs/exName.log). Then, on the server, we can handle that POST request by saving the .log data we received to the file path specified in the URL.

It is unfortunate to have the extra Python script, but it solves the "how do we save the '.log' file to the specific path that we want in an automated way without requiring the user to just do it themselves" problem that we have.

@raysan5

raysan5 commented Sep 2, 2026 •

Copy link
Copy Markdown
Owner

@MatthewRoush thanks for the detailed explanation but still I prefer let the user manage it manually than adding a Python script dependency.

EDIT: Not sure if some of the parts of this PR could also be implemented without the script addition.

@raysan5 raysan5 closed this Sep 2, 2026
@MatthewRoush

Copy link
Copy Markdown
Contributor Author

Yeah, the two small changes (fixing the Makefile and changing the port number) are unrelated to the script, everything else relies on the script.

MatthewRoush added a commit to MatthewRoush/raylib that referenced this pull request Sep 4, 2026
See raysan5#6111 for more details.

The primary annoyance with the previous implementation was that it couldn't save a file to a specific path because of browser security restrictions. This means that the file is automatically (or not, if the user has the setting on that makes it prompt every time) saved to the "default" save location, which may not be the traditional "Downloads" directory.

The way to bypass the client-side file saving restrictions is to not save the file from the client, but instead from the server (which is also just the client computer, because it's a `localhost://`.) The problem is that the default server from running `python http.server` (which is what we previously did to run the web exmaples) doesn't handle `POST` requests. That means we have to write our own Python script to implement `POST` request handling. We also have to handle `GET` requests since we're using our own request handling logic, as far as I know.

The `XMLHttpRequest()` sends the `POST` request from the client to the server, and the Python script (our server) handles that `POST` request. We can send a `POST` request containing the `.log` data, with the URL being the path (relative to the server root) we want to save the `.log` file to (`exBasePath/exCategory/logs/exName.log`). Then, on the server, we can handle that `POST` request by saving the `.log` data we received to the file path specified in the URL.

Saving the `.log` file to specific, known location, is especially helpful for `rexm textlog`, which needs to be able to find the `.log` file.
MatthewRoush added a commit to MatthewRoush/raylib that referenced this pull request Sep 8, 2026
See raysan5#6111 for more details.

The primary annoyance with the previous implementation was that it couldn't save a file to a specific path because of browser security restrictions. This means that the file is automatically (or not, if the user has the setting on that makes it prompt every time) saved to the "default" save location, which may not be the traditional "Downloads" directory.

The way to bypass the client-side file saving restrictions is to not save the file from the client, but instead from the server (which is also just the client computer, because it's a `localhost://`.) The problem is that the default server from running `python http.server` (which is what we previously did to run the web exmaples) doesn't handle `POST` requests. That means we have to write our own Python script to implement `POST` request handling. We also have to handle `GET` requests since we're using our own request handling logic, as far as I know.

The `XMLHttpRequest()` sends the `POST` request from the client to the server, and the Python script (our server) handles that `POST` request. We can send a `POST` request containing the `.log` data, with the URL being the path (relative to the server root) we want to save the `.log` file to (`exBasePath/exCategory/logs/exName.log`). Then, on the server, we can handle that `POST` request by saving the `.log` data we received to the file path specified in the URL.

Saving the `.log` file to specific, known location, is especially helpful for `rexm textlog`, which needs to be able to find the `.log` file.
MatthewRoush added a commit to MatthewRoush/raylib that referenced this pull request Sep 16, 2026
See raysan5#6111 for more details.

The primary annoyance with the previous implementation was that it couldn't save a file to a specific path because of browser security restrictions. This means that the file is automatically (or not, if the user has the setting on that makes it prompt every time) saved to the "default" save location, which may not be the traditional "Downloads" directory.

The way to bypass the client-side file saving restrictions is to not save the file from the client, but instead from the server (which is also just the client computer, because it's a `localhost://`.) The problem is that the default server from running `python http.server` (which is what we previously did to run the web exmaples) doesn't handle `POST` requests. That means we have to write our own Python script to implement `POST` request handling. We also have to handle `GET` requests since we're using our own request handling logic, as far as I know.

The `XMLHttpRequest()` sends the `POST` request from the client to the server, and the Python script (our server) handles that `POST` request. We can send a `POST` request containing the `.log` data, with the URL being the path (relative to the server root) we want to save the `.log` file to (`exBasePath/exCategory/logs/exName.log`). Then, on the server, we can handle that `POST` request by saving the `.log` data we received to the file path specified in the URL.

Saving the `.log` file to specific, known location, is especially helpful for `rexm textlog`, which needs to be able to find the `.log` file.
MatthewRoush added a commit to MatthewRoush/raylib that referenced this pull request Sep 16, 2026
See raysan5#6111 for more details.

The primary annoyance with the previous implementation was that it couldn't save a file to a specific path because of browser security restrictions. This means that the file is automatically (or not, if the user has the setting on that makes it prompt every time) saved to the "default" save location, which may not be the traditional "Downloads" directory.

The way to bypass the client-side file saving restrictions is to not save the file from the client, but instead from the server (which is also just the client computer, because it's a `localhost://`.) The problem is that the default server from running `python http.server` (which is what we previously did to run the web exmaples) doesn't handle `POST` requests. That means we have to write our own Python script to implement `POST` request handling. We also have to handle `GET` requests since we're using our own request handling logic, as far as I know.

The `XMLHttpRequest()` sends the `POST` request from the client to the server, and the Python script (our server) handles that `POST` request. We can send a `POST` request containing the `.log` data, with the URL being the path (relative to the server root) we want to save the `.log` file to (`exBasePath/exCategory/logs/exName.log`). Then, on the server, we can handle that `POST` request by saving the `.log` data we received to the file path specified in the URL.

Saving the `.log` file to specific, known location, is especially helpful for `rexm textlog`, which needs to be able to find the `.log` file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants